import {h} from "vue"
import {NButton, NIcon, NPopconfirm} from "naive-ui"
import {
    EyeOutline as viewIcon,
    RemoveCircleOutline as removeIcon,
} from "@vicons/ionicons5"
import {Edit as editIcon} from "@vicons/carbon"

/**
 * 行内查看按钮
 * @param handlerFun
 * @param params
 */
export const rowViewButton = (handlerFun: any, params: any) => {
    return h(
        NButton,
        {
            strong: true,
            quaternary: true,
            type: "success",
            size: "small",
            class: "ml-2",
            onClick: () => handlerFun(params),
        },
        {
            default: () => [
                h(
                    NIcon,
                    {
                        component: viewIcon,
                        class: "mr-1",
                    },
                ),
                "查看",
            ],
        },
    )
}

/**
 * 行内编辑按钮
 * @param handlerFun
 * @param params
 */
export const rowEditButton = (handlerFun: any, params: any) => {
    return h(
        NButton,
        {
            strong: true,
            quaternary: true,
            type: "info",
            size: "small",
            class: "ml-2",
            onClick: () => handlerFun(params),
        },
        {
            default: () => [
                h(
                    NIcon,
                    {
                        component: editIcon,
                        class: "mr-1",
                    },
                ),
                "修改",
            ],
        },
    )
}

/**
 * 行内删除按钮
 * @param handlerFun
 * @param params
 */
export const rowDeleteButton = (handlerFun: any, params: any) => {
    return h(
        NPopconfirm,
        {
            onPositiveClick: () => handlerFun(params),
        },
        {
            trigger: () => h(
                NButton,
                {
                    strong: true,
                    quaternary: true,
                    type: "error",
                    size: "small",
                    class: "ml-2",
                },
                {
                    default: () => [
                        h(
                            NIcon,
                            {
                                component: removeIcon,
                                class: "mr-1",
                            },
                        ),
                        "删除",
                    ],
                },
            ),
            default: () => "确认删除?",
        },
    )
}
